package com.saxon.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.saxon.springcloud.pojo.Dept;
import com.saxon.springcloud.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
public class DeptCotroller {
    @Autowired
    DeptService deptService;

    @GetMapping ("/get/{id}")
    @HystrixCommand(fallbackMethod = "defaultDept")
    public Dept queryDeptById (@PathVariable ("id") long id) {
        Dept dept = deptService.queryDeptById (id);
        if (dept==null){
            throw new RuntimeException ();
        }
        return dept;
    }

    public Dept defaultDept(@PathVariable("id") long id){
        return new Dept ().setDeptno (id).setDb_source ("没有这个数据").setDeptname ("没有这个数据====》@hystrix");
    }

}
